<template>
  <el-form ref="roleFormRef"
    :model="form"
    :rules="rules"
    class="rk-form">
    <el-row class="mb20">
      <el-col :span="12">
        <el-form-item label="角色编码"
          prop="code"
          label-width="120">
          <el-input v-model="form.code"
            :disabled="isEdit"
            placeholder="请输入角色编码" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="角色名称"
          prop="name"
          label-width="120">
          <el-input v-model="form.name"
            placeholder="请输入角色名称" />
        </el-form-item>
      </el-col>
    </el-row>

    <el-row class="mb20">
      <el-col :span="12">
        <el-form-item label="角色类别"
          prop="roleType"
          label-width="120">
          <rk-select style="width: 100%"
            v-model="form.roleType"
            :is-search="false"
            :options="toArray(ROLE_TYPE_ENUMS)">
          </rk-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="所属区划"
          prop="adName"
          label-width="120">
          <el-input v-model="form.adName"
            disabled />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row class="mb20">
      <el-col :span="12">
        <el-form-item label="状态"
          prop="status"
          label-width="120">
          <rk-select :is-search="false"
            style="width: 100%"
            v-model="form.status"
            :options="toArray(COMMON_STOP_OPEN_ENUMS)">
          </rk-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="是否共享"
          prop="issys"
          label-width="120">
          <rk-select style="width: 100%"
            v-model="form.issys"
            :is-search="false"
            :options="toArray(ROLE_SHARE_STATUS_ENUMS)">
          </rk-select>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row class="mb20">
      <el-col :span="24">
        <el-form-item label="说明"
          prop="remark"
          label-width="120">
          <el-input v-model="form.remark"
            placeholder="请输入说明" />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>

</template>

<script setup>

import { inject, onMounted, reactive, ref, } from "vue";
import { COMMON_STOP_OPEN_ENUMS, COMMON_STOP_OPEN_MT_ENUMS, toArray } from "@/enums/enums-common.js";
import { ROLE_SHARE_STATUS_ENUMS, ROLE_TYPE_ENUMS } from "@/enums/enums-role.js";

const roleFormRef = ref(null)

const props = defineProps({
  roleModel: {
    type: Object,
    default: {}
  },
  isEdit: {
    type: Boolean,
    default: false
  }
})
const form = reactive({
  agency: "",
  code: "",
  division: "",
  guid: "",
  issys: 0,
  name: "",
  province: "",
  remark: "",
  roleType: 0,
  status: "1"

})

const treeParams = inject('treeParams')

const rules = {
  code: [{ required: true, message: '请输入角色编码', trigger: 'blur' }],
  name: [{ required: true, message: '请输入角色名称', trigger: 'blur' }],
  roleType: [{ required: true, message: '请选择角色类别', trigger: 'change' }],
  status: [{ required: true, message: '请选择状态', trigger: 'change' }],
  issys: [{ required: true, message: '请选择是否共享', trigger: 'change' }]
}

const getFormData = () => {
  return Object.assign({}, form)
}
/** 表单校验 */
const validateForm = async () => {
  if (!roleFormRef.value) return false
  return await roleFormRef.value.validate()

}
defineExpose({
  getFormData,
  validateForm
})
onMounted(() => {
  Object.assign(form, props.roleModel, { adName: `${treeParams.adCode} ${treeParams.adName}` })
  // console.log(form);
})


</script>

<style lang="scss" scoped>
</style>
